using System;
using System.Collections.Generic;
using System.Text;

namespace eLib
{
    /// <summary>
    /// caption for frmBG.StepCaption
    /// </summary>
    /// <param name="ws"></param>
    /// <param name="caption"></param>
    public delegate void CalcDelegate(WorkSpace ws, out string caption);

    public delegate double SimpleCalc(double[] args);

    public static class CalcFunctions
    {
        public static double div(double[] args)
        {
            double res = 0;
            if (args.Length >= 2 && args[1] != 0)
                res = args[0] / args[1];
            return res;
        }
        public static double sum(double[] args)
        {
            double res = 0;
            foreach (double d in args) res += d;
            return res;
        }
        public static double substract(double[] args)
        {
            switch (args.Length)
            {
                case 0: return 0;
                case 1: return args[0];
                default:
                    double res = args[0];
                    for (int i = 1; i < args.Length; i++)
                        res -= args[i];
                    return res;
            }
        }
        public static double multi(double[] args)
        {
            double res = 1;
            if (args.Length > 0) foreach (double d in args) res *= d;
            else res = 0;
            return res;
        }
        public static double first(double[] args)
        {
            double res = 0;
            if (args.Length > 0) res = args[0];
            return res;
        }
    }
}
